﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Infrastructure;
using Framework;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

namespace CodeFirstDomain.Model
{
    public class User : DbEntity, IAggregateRoot
    {
        public User()
        {
            Address = new Address();
            MBlogs = new HashSet<MBlog>();
        }

        [JsonProperty("id")]
        public Guid ID
        {
            get;set;
        }

        [JsonProperty("text")]
        public string Name
        {
            get; set;
        }

        [JsonIgnore]
        public virtual Address Address{get;set;}

        [JsonProperty("leaf")]
        [NotMapped]
        public bool HasMblog
        {
            get
            {
                return this.GetQueryable(u => u.MBlogs).Count() == 0;
            }
        }
        [JsonProperty("type")]
        [NotMapped]
        public string Type
        {
            get { return "USER"; }
        }

        [JsonIgnore]
        public ICollection<MBlog> MBlogs
        {
            get;set;
        }

        [JsonIgnore]
        internal IEnumerable<MBlog> SpecialMBlogs
        {
            get
            {
                return this.GetQueryable(u => u.MBlogs).Where(mb => mb.Body.Contains("2"));
            }
        }
    }
}
